<template>
  <div class="hello">
      <van-nav-bar
  title="编辑信息"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
    <h2>编辑个人信息</h2>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        label="用户名"
      />
      <van-field
        v-model="password"
        type="password"
        label="密码"
      />
       <van-field
        v-model="phone"
        label="电话"
      />
      <van-field
        v-model="age"
        label="年龄"
      />
      <van-field
        v-model="gender"
        label="性别"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
import { Toast } from 'vant';
export default {
  name: "Code",
  data() {
    return {
      msg: "Welcome to Your Vue.js App",
      username:"",
      password:"",
      phone:"",
      age:"",
      gender:""
    }
  },
  methods:{
      onSubmit(){
          var token = sessionStorage.getItem("token");
          var str = `id=${this.getInfo.id}&token=${token}&phone=${this.phone}&name=${this.username}
          &password=${this.password}&age=${this.age}&gender=${this.gender}`
          this.axios.post("http://123.57.130.65:8080/user/updateCheckById",str).then(res=>{
              console.log(res)
              if(res.data.code==200){
                  Toast(res.data.message);
                  this.$store.commit("saveInfo",res.data.data);
                  this.$router.go(-1);
              }else{
                  Toast(res.data.message);
              }
          }) 
      },
        onClickLeft(){
            this.$router.go(-1);
        }
  },
  computed: {
    getInfo() {
      return this.$store.state.info;
    },
  },
};
</script>
<style scoped>

</style>
